package com.lagou.mr.homework;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;


import java.io.IOException;

public class wordOrderDriver {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {

        //获取配置文件，获取任务实例
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf,"wordOrderDriver");

        //指定jar路径
        job.setJarByClass(wordOrderDriver.class);

        //指定Mapper和Reducer路径
        job.setMapperClass(wordOrderMapper.class);
        job.setReducerClass(wordOrderReducer.class);

        //指定Mapper输出的kv
        job.setMapOutputKeyClass(LongWritable.class);
        job.setMapOutputValueClass(NullWritable.class);

        //指定输出文件的KV
        job.setOutputKeyClass(IntWritable.class);
        job.setOutputValueClass(LongWritable.class);

        //指定输出成一个文件
        job.setNumReduceTasks(1);

        //指定输入输出的文件路径
        FileInputFormat.setInputPaths(job,new Path("G:\\orderInput"));
        FileOutputFormat.setOutputPath(job,new Path("G:\\orderOutput"));
        boolean flag = job.waitForCompletion(true);

        System.exit(flag ? 0 : 1);


    }
}
